<template>
	<u-popup v-model="show" mode="center" :mask-close-able="false" border-radius="16" background-color="transparent"
		@close="handleClose">
		<view class="form-popup-content">
			<view class="popup-header">
				<text>确认师傅上门地址</text>
			</view>
			<view class="form-content">
				<view class="form-item">
					<view class="form-label">
						<text>联系人姓名</text>
					</view>
					<view class="item-content">
						<input v-model="formData.name" placeholder="请输入联系人姓名" class="form-input" />
					</view>
				</view>
				<view class="form-item">
					<view class="form-label">
						<text>联系人手机</text>
					</view>
					<view class="item-content">
						<input v-model="formData.mobile" placeholder="请输入联系人手机" class="form-input" />
					</view>
				</view>
				<!-- 	<view class="form-item">
					<view class="form-label">
						<text>联系人地址</text>
					</view>
					<view class="item-content">
						<input placeholder="请输入联系人地址" class="form-input" />
					</view>
				</view> -->
				<view class="form-item">
					<view class="form-label">
						<text>详细地址</text>
					</view>
					<view class="item-content">
						<textarea v-model="formData.xiangxi_address" placeholder="请输入详细地址" class="form-textarea" />
					</view>
				</view>
			</view>
			<view class="form-footer">
				<view class="footer-btn" @click="handleClose">
					<text>取消</text>
				</view>
				<view class="footer-btn active" @click="handleConfirm">
					<text>确定</text>
				</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
	import { toast } from '@/utils/tool'
	const getFormData = () => ({
		name: "",
		mobile: "",
		xiangxi_address: ""
	})
	export default {
		data() {
			return {
				show: false,
				formData: getFormData()
			}
		},
		emits: ['confirm'],
		methods: {
			handleConfirm() {
				const { name, mobile, xiangxi_address } = this.formData
				if (!name) return toast({ title: "请输入联系人姓名" })
				if (!mobile) return toast({ title: "请输入联系人电话" })
				if (!xiangxi_address) return toast({ title: "请输入地址" })
				this.$emit("confirm", {
					name,
					mobile,
					xiangxi_address
				})
				this.handleClose()
			},
			handleClose() {
				this.show = false
				this.onClose()
			},
			onClose() {
				setTimeout(() => {
					this.formData = getFormData()
				}, 300)
			},
			open() {
				this.show = true
			}
		},
	}
</script>

<style lang="scss" scoped>
	.form-popup-content {
		width: 600rpx;
		box-sizing: border-box;
		position: relative;
		border-radius: 16rpx;

		.form-footer {
			display: flex;
			align-items: center;
			flex-flow: row nowrap;
			border-radius: 0 0 16rpx 16rpx;

			.footer-btn {
				flex: 1;
				padding: 24rpx 0;
				text-align: center;
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
				line-height: 34rpx;
				background-color: #fff;

				&.active {
					color: #FFFFFF;
					background-color: #3361F0;
				}
			}
		}

		.form-content {
			padding: 30rpx 20rpx 26rpx;
			background-color: #FFFFFF;
			box-sizing: border-box;
			position: relative;
			width: 100%;

			.form-item {
				margin-bottom: 20rpx;

				&:last-child {
					margin-bottom: 0;
				}

				.item-content {
					margin-top: 4rpx;
					width: 100%;
					box-sizing: border-box;

					.form-textarea {
						width: 100%;
						box-sizing: border-box;
						height: 140rpx;
						line-height: 32rpx;
						background: #EFF2F6;
						padding: 18rpx 12rpx;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
					}

					.form-input {
						width: 100%;
						box-sizing: border-box;
						height: 60rpx;
						line-height: 60rpx;
						background: #EFF2F6;
						padding: 0 12rpx;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
					}
				}

				.form-label {
					font-size: 28rpx;
					color: #313145;
					line-height: 38rpx;

					&::before {
						content: "*";
						color: #FF0000;
					}
				}
			}
		}

		.popup-header {
			padding: 24rpx;
			text-align: center;
			background: #3361F0;
			border-radius: 16rpx 16rpx 0rpx 0rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #FFFFFF;
			line-height: 32rpx;
		}
	}
</style>